package com.xq.jltx.launchactivitypro;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016/05/27.
 */
public class FlagActivityB extends AppCompatActivity implements View.OnClickListener{
    private TextView tv;
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private Button btn6;
    private String CLASSTAG = "";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CLASSTAG = this.getClass().getSimpleName();
        setContentView(R.layout.activity_flag);
        if(savedInstanceState != null){
            XqLog.e(LogConfig.TAG,CLASSTAG+".onCreate=>savedInstanceState != null");
        }else{
            Log.e(LogConfig.TAG,CLASSTAG+".onCreate=>savedInstanceState == null");
        }
        initView();
        tv.setText(CLASSTAG+this.toString());
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);
        btn6.setOnClickListener(this);
    }

    private void initView(){
        tv = (TextView)this.findViewById(R.id.tv);
        btn1 = (Button)this.findViewById(R.id.btn1);
        btn2 = (Button)this.findViewById(R.id.btn2);
        btn3 = (Button)this.findViewById(R.id.btn3);
        btn4 = (Button)this.findViewById(R.id.btn4);
        btn5 = (Button)this.findViewById(R.id.btn5);
        btn6 = (Button)this.findViewById(R.id.btn6);
    }


    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()){
            case R.id.btn1:
                intent = new Intent();
                intent.setClass(this,FlagActivityA.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
                break;
            case R.id.btn2:
                intent = new Intent();
                intent.setClass(this,FlagActivityB.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            case R.id.btn3:
                intent = new Intent();
                intent.setClass(this,FlagActivityC.class);
                startActivity(intent);
                break;
            case R.id.btn4:
                intent = new Intent();
                intent.setClass(this,FlagActivityD.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  //当启动该activity如果该activity已经在任务栈中有存在实例，那么会将所有位于它上面的Activity都要被出栈，这个模式一般需要和FLAG_ACTIVITY_NEW_TASK一起配合使用
//                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            case R.id.btn5:
                intent = new Intent();
                intent.setClass(this,MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);  //清除已存在的所有task里面的activity，并且开辟一个新的task来装载新的activity，一般用来强制回到登录界面或者首页
                startActivity(intent);
                break;
            case R.id.btn6:
                intent = new Intent();
                intent.setClass(this,FlagActivityF.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);   //不记录activity到activity栈中
                startActivity(intent);
                break;
            default:
        }
    }


    @Override
    protected void onNewIntent(Intent intent) {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onNewIntent");
        super.onNewIntent(intent);
    }

    @Override
    protected void onStart() {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onStart");
        super.onStart();
    }

    @Override
    protected void onRestart() {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onRestart");
        super.onRestart();
    }

    @Override
    protected void onResume() {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onResume");
        super.onResume();
    }

    @Override
    protected void onPause() {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onPause");
        super.onPause();
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onSaveInstanceState(outState,outPersistentState)");
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onSaveInstanceState(outState)");
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onRestoreInstanceState(savedInstanceState,persistentState)");
        super.onRestoreInstanceState(savedInstanceState, persistentState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onRestoreInstanceState(savedInstanceState)");
        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    protected void onStop() {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onStop");
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        XqLog.e(LogConfig.TAG,CLASSTAG+".onDestroy");
        super.onDestroy();
    }

}
